import base64toBlob from './base64toBlob';
/**
 * @category  base64格式转Blob格式下载
 * @description  base64格式转Blob格式下载
 * @param data {string} base64格式文件
 * @param fileName {string} 文件名称
 * @example DownLoadBlobFile(data) 
 */
export default function downLoadBlobFile(data: string, fileName = "文件") {
  const blob = new Blob([base64toBlob(data)], {
    type:
      "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
  });
  const elink = document.createElement("a");
  if ("download" in elink) {
    // 非IE下载
    elink.download = fileName;
    elink.style.display = "none";
    elink.href = URL.createObjectURL(blob);
    document.body.appendChild(elink);
    elink.click();
    URL.revokeObjectURL(elink.href); // 释放URL 对象
    document.body.removeChild(elink);
  }
};